| Conditions | 3 |
| Paths | 2 |
| Total Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import fse from 'fs-extra' |
||
| 10 | export function saveJson(url, json) { |
||
| 11 | mkdirp.sync(path.dirname(url)) |
||
| 12 | |||
| 13 | if(typeof json.abe_source !== 'undefined' && json.abe_source !== null) { |
||
| 14 | delete json.abe_source |
||
| 15 | } |
||
| 16 | |||
| 17 | var eachRecursive = function (obj) { |
||
| 18 | for (var k in obj) { |
||
|
|
|||
| 19 | if (typeof obj[k] === 'object' && obj[k] !== null){ |
||
| 20 | eachRecursive(obj[k]) |
||
| 21 | } else if (typeof obj[k] !== 'undefined' && obj[k] !== null){ |
||
| 22 | obj[k] = xss(obj[k].toString().replace(/"/g, '"'), { 'whiteList': config.htmlWhiteList }) |
||
| 23 | } |
||
| 24 | } |
||
| 25 | } |
||
| 26 | |||
| 27 | eachRecursive(json) |
||
| 28 | |||
| 29 | fse.writeJsonSync(url, json, { |
||
| 30 | space: 2, |
||
| 31 | encoding: 'utf-8' |
||
| 32 | }) |
||
| 33 | return true |
||
| 34 | } |
||
| 35 | |||
| 41 | } |
When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically: